﻿using System;
using System . Collections . Generic;
using System . IO;
using System . Linq;
using System . Runtime . InteropServices . WindowsRuntime;
using Windows . Foundation;
using Windows . Foundation . Collections;
using Windows . UI . Xaml;
using Windows . UI . Xaml . Controls;
using Windows . UI . Xaml . Controls . Primitives;
using Windows . UI . Xaml . Data;
using Windows . UI . Xaml . Input;
using Windows . UI . Xaml . Media;
using Windows . UI . Xaml . Navigation;
using WenceyWang . RichMan4L . App . Logic;


namespace WenceyWang . RichMan4L . App . Pages
{
	/// <summary>
	/// 可用于自身或导航至 Frame 内部的空白页。
	/// </summary>
	public sealed partial class MainPage : Page
	{
		public MainPage ( )
		{
			this . InitializeComponent ( );
			this . Loaded += MainPage_Loaded;
			this . SizeChanged += MainPage_SizeChanged; ;
		}

		private void MainPage_SizeChanged ( object sender , SizeChangedEventArgs e )
		{
			if ( e . NewSize . Height < e . NewSize . Width && e . NewSize . Width >= 640 )
			{
				VisualStateManager . GoToState ( this , nameof ( Wide ) , false );
			}
			else
			{
				VisualStateManager . GoToState ( this , nameof ( Mobile ) , false );

			}
		}

		protected override void OnNavigatedTo ( NavigationEventArgs e )
		{

			// TODO: Prepare page for display here.

			// TODO: If your application contains multiple pages, ensure that you are
			// handling the hardware Back button by registering for the
			// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
			// If you are using the NavigationHelper provided by some templates,
			// this event is handled for you.
			//Windows.Phone.UI.Input.HardwareButtons.
		}
		private void MainPage_Loaded ( object sender , RoutedEventArgs e )
		{
			StartStoryBoard . Begin ( );
			StartStoryBoard . Completed += StartStoryBoard_Completed;
		}

		private void StartStoryBoard_Completed ( object sender , object e )
		{
			if ( new AppSettings ( ) . OCDMode )
			{
				MainGrid . TurnOnOCDMode ( );
			}
			StartStoryBoard . Completed -= StartStoryBoard_Completed;
		}

		private void NewGameButton_Click ( object sender , RoutedEventArgs e )
		{
			PageNavigateHelper . Navigate ( typeof ( CreateGamePage ) , new StartGameParameters ( ) , "Lime" , LeaveStoryBoard , BackGroundRect , Frame , RemoveControl , AddControl );
		}
		private void SettingButton_Click ( object sender , RoutedEventArgs e )
		{
			PageNavigateHelper . Navigate ( typeof ( SettingPage ) , null , "DeepRed" , LeaveStoryBoard , BackGroundRect , Frame , RemoveControl , AddControl );
		}

		private void RemoveControl ( )
		{
			NewGameButton . Click -= NewGameButton_Click;
			SettingButton . Click -= SettingButton_Click;
		}

		private void AddControl ( )
		{
			NewGameButton . Click += NewGameButton_Click;
			SettingButton . Click += SettingButton_Click;
		}

		private void LoadGameButton_Click ( object sender , RoutedEventArgs e )
		{
			PageNavigateHelper . Navigate ( typeof ( LoadGamePage ) , null , "Black" , LeaveStoryBoard , BackGroundRect , Frame , RemoveControl , AddControl );
		}


	}
}
